import angular from "angular"

const serverName = "rentDetailServer"
angular.module('rentDetail')
    .service(serverName, ['$http', "Upload", function ($http, Upload) {
        return {
            getDetailList(contractId) {
                return $http.get("/api/index.php?r=contract/get-ad-organization-info", {
                    params: { contractId }
                })
            },
            addAdList(params, data) {
                return Upload.upload({
                    url: `/api/index.php?r=contract/add-ad-list`,
                    params,
                    data,
                    headers: {
                        "Content-Type": "form-data"
                    },
                    USE_FORM_DATA: false
                })
            },
            editAdList(params, data) {
                return Upload.upload({
                    url: `/api/index.php?r=contract/edit-ad-list`,
                    params,
                    data,
                    headers: {
                        "Content-Type": "form-data"
                    },
                    USE_FORM_DATA: false
                })
            },
            delAdList({ contractId, Id }) {
                return $http.post("/api/index.php?r=contract/del-ad-list", {}, {
                    params: { contractId, Id }
                })
            },
            delAdPdf({ contractId, Id }) {
                return $http.post("/api/index.php?r=contract/del-ad-pdf", {}, {
                    params: { contractId, Id }
                })
            }
        }
    }]).filter('myCurrency', [() => {
        return function (amount) {
            if (!amount) {
                return amount;
            }
            amount = Number(amount)
            const isNegate = amount < 0;
            const s = Math.abs(amount).toFixed(2)
            const d = s.replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,")
            return `￥ ${isNegate ? "-" : ""}${d}`;
        }
    }]);
export default serverName